import { NextApiRequest, NextApiResponse } from "next";
import { prisma } from "../../components/db";

import { getSession } from "next-auth/react";

const ProfileHandler = async (req: NextApiRequest, res: NextApiResponse) => {
  const session = await getSession({ req });

  if (session) {
    const profile = await prisma.user.findUnique({
      where: {
        id: session.user.id,
      },
    });
    res.send(profile);
  } else {
    res.status(401);
  }
  res.end();
};

export default ProfileHandler;
